package com.fancon.rage.comic.vn.gui;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.fancon.rage.comic.vn.R;
import com.fancon.rage.comic.vn.entity.Photo;

/**
 * Custome view for VN mode
 * 
 * @author binhbt 2012
 */
public class ComicVnView extends FrameLayout {
	private Context mContext;
	private ViewPager myPager;
	private Paginator mPaginator;

	public ComicVnView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		// TODO Auto-generated constructor stub
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = layoutInflater.inflate(R.layout.rage_vn_view, this);
		myPager = (ViewPager) findViewById(R.id.slide_bar);
		mPaginator = (Paginator) findViewById(R.id.paginator);
	}

	public void loadPhotos(ArrayList<Photo> photos) {
		// if(photos != null){
		PageViewAdapter adapter = new PageViewAdapter((Activity) mContext,
				photos, mPaginator, TopControlView.VN_MODE);
		myPager.setAdapter(adapter);
		myPager.setCurrentItem(0);
		myPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				mPaginator.selectedPage(arg0);
			}

		});
		// }
	}
}
